package com.zgw.his.design.model.widgets;

import org.eclipse.swt.graphics.Image;
import org.eclipse.wb.core.gef.policy.selection.NonResizableSelectionEditPolicy;
import org.eclipse.wb.draw2d.Figure;
import org.eclipse.wb.draw2d.geometry.Point;
import org.eclipse.wb.gef.core.policies.EditPolicy;
import org.eclipse.wb.gef.graphical.GraphicalEditPart;
import org.eclipse.wb.internal.core.gef.part.nonvisual.BeanFigure;
import org.eclipse.wb.internal.core.model.nonvisual.NonVisualBeanInfo;
import org.eclipse.wb.internal.core.model.util.ObjectsLabelProvider;

public class DatasetEditPart extends GraphicalEditPart {

	private final DatasetInfo m_beanInfo;

	// //////////////////////////////////////////////////////////////////////////
	//
	// Constructor
	//
	// //////////////////////////////////////////////////////////////////////////
	public DatasetEditPart(DatasetInfo javaInfo) {
		m_beanInfo = javaInfo;
		setModel(javaInfo);
	}

	// //////////////////////////////////////////////////////////////////////////
	//
	// Policy
	//
	// //////////////////////////////////////////////////////////////////////////
	@Override
	protected void createEditPolicies() {
		installEditPolicy(EditPolicy.SELECTION_ROLE,
				new NonResizableSelectionEditPolicy());
		installEditPolicy(new DatasetEditPolicy(m_beanInfo));
	}

	// //////////////////////////////////////////////////////////////////////////
	//
	// Figure
	//
	// //////////////////////////////////////////////////////////////////////////
	@Override
	protected Figure createFigure() {
		Image image = ObjectsLabelProvider.INSTANCE.getImage(m_beanInfo);
		return new BeanFigure(image);
	}

	@Override
	protected void refreshVisuals() {
		String text = ObjectsLabelProvider.INSTANCE.getText(m_beanInfo);
		BeanFigure figure = (BeanFigure) getFigure();
		figure.update(text, new Point(6, 300));
	}

	@Override
	protected void refreshChildren() {
		super.refreshChildren();
	}

}
